package com.hooenergy.etl.test.user;

import com.hooenergy.etl.starter.core.IQueryDao;
import com.hooenergy.etl.test.Do.StudentDo;
import org.apache.ibatis.annotations.Param;

import java.util.Date;
import java.util.List;
import java.util.Map;

public interface BIQueryDao extends IQueryDao<StudentDo> {



    Long countByQuery(@Param("queryMap") Map<String, Object> queryMap, @Param("startTime") Date startTime, @Param("endTime") Date endTime, @Param("key") Long key);




    List<StudentDo> findByQueryLimit(@Param("queryMap") Map<String, Object> queryMap, @Param("startTime") Date startTime, @Param("endTime") Date endTime, @Param("key") Long key,
                                     long offset, long size);


    List<StudentDo> findByQuery(@Param("queryMap") Map<String, Object> queryMap, @Param("startTime") Date startTime, @Param("endTime") Date endTime, @Param("key") Long key);


    @Override
    default Long total(Map<String, Object> queryMap, Long start, Long end, String key) {
        if(start != null && end != null){
            Date startDt = new Date(start);
            Date endDt = new Date(end);
            return this.countByQuery(queryMap, startDt, endDt, Long.parseLong(key));
        }
        return this.countByQuery(queryMap, null, null, Long.parseLong(key));
    }


    @Override
    default List<StudentDo> find(Map<String, Object> queryMap, Long start, Long end, String key, long offset, long size){
        if(start != null && end != null){
            Date startDt = new Date(start);
            Date endDt = new Date(end);
            return this.findByQueryLimit(queryMap, startDt, endDt, Long.parseLong(key), offset, size);
        }
        return this.findByQueryLimit(queryMap, null, null, Long.parseLong(key), offset, size);
    }

    @Override
    default List<StudentDo> find(Map<String, Object> queryMap, Long start, Long end, String key){
        if(start != null && end != null){
            Date startDt = new Date(start);
            Date endDt = new Date(end);
            return this.findByQuery(queryMap, startDt, endDt, Long.parseLong(key));
        }
        return this.findByQuery(queryMap, null, null, Long.parseLong(key));
    }
}
